package per.dg.retrofittestkotlin

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.JsonObject
import okhttp3.ResponseBody
import per.dg.retrofittestkotlin.project.HomeActivity
import per.dg.retrofittestkotlin.use.RetrofitHttpManager
import per.dg.retrofittestkotlin.use.RetrofitHttpManagerFactory
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.lang.String

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        startActivity(Intent(this, HomeActivity::class.java))

        var retrofitHttpManager : RetrofitHttpManager = RetrofitHttpManagerFactory().creat()
        var callRegist : Call<ResponseBody> = retrofitHttpManager.wanAndroidApi.regist("bin", "123456", "123456")
        callRegist.enqueue(object : Callback<ResponseBody> {
            override fun onFailure(call: Call<ResponseBody>?, t: Throwable?) {
                Log.e("onFailure: ", t.toString()+""+call.toString())
            }

            override fun onResponse(call: Call<ResponseBody>?, response: Response<ResponseBody>?) {
                var ob:ResponseBody? = response?.body()
                Log.e("onResponse: ", String(ob?.bytes()).toString())
            }

        })

        var callLogin : Call<JsonObject> = retrofitHttpManager.wanAndroidApi.login("bin", "123456")
        callLogin.enqueue(object : Callback<JsonObject> {
            override fun onFailure(call: Call<JsonObject>?, t: Throwable?) {
                Log.e("onFailure: ", t.toString()+""+call.toString())
            }

            override fun onResponse(call: Call<JsonObject>?, response: Response<JsonObject>?) {
                var ob:JsonObject? = response?.body()

                Log.e("onResponse: ", ob.toString())
            }

        })

    }
}